import BaseApi, {APIBaseURL} from '../BaseApi';

const controller = "/commonDevice";

export default {
    /**
     * @description 获取设备信息列表
     * @author wenlang
     * @date 2019/7/12
     */
    getCommonDeviceInfoList(condition) {
        return this.requestPost(controller, "/getCommonDeviceInfoList", condition);
    },

    /**
     * @description 更新设备信息（同步更新与车位的绑定关系）
     * @author wenlang
     * @date 2019/7/12
     */
    updateCommonDevice(updateItems) {
        return this.requestPost(controller, "/updateCommonDeviceBind", updateItems);
    },

    /**
     * @description 新增一个设备
     * @author wenlang
     * @date 2019/7/12
     */
    addOneCommonDevice(imei) {
        return this.requestPost(controller, "/addOneCommonDevice", imei);
    },

    /**
     * @description 删除一个设备（逻辑删除）
     * @author wenlang
     * @date 2019/7/12
     */
    delCommonDevice(deviceId) {
        return this.requestPostForJson(controller, "/delCommonDevice", deviceId);
    },

    /**
     * @description 下载设备导入excel模板
     * @author wenlang
     * @date 2019/7/12
     */
    downCommonDeviceImportTemplate() {
        return this.requestDownLoadGet(controller, "/downCommonDeviceImportTemplate", null);
    },
    /**
     * 导出列表查询数据
     * @returns {*}
     */
    downloadCommonDeviceInfoList(condition) {
        return this.requestDownloadGet(controller, "/downCommonDeviceInfoList", condition);
    },
    /**
     * @description 导入设备数据
     * @author wenlang
     * @date 2019/7/12
     */
    importCommonDeviceData(condition) {
        return this.requestMultipartPost(controller, "/importCommonDeviceData", condition);
    },


    /**
     * @description 日志记录查询
     * @author wenlang
     * @date 2019/7/12
     */
    getDeviceLogRecordList(condition) {
        return this.requestPost(controller, "/getDeviceLogRecordList", condition);
    },

    /**
     * @description 心跳记录查询
     * @author wenlang
     * @date 2019/7/12
     */
    getDeviceHeartbeatRecordList(condition) {
        return this.requestPost(controller, "/getDeviceHeartbeatRecordList", condition);
    },

    /**
     * @description 主动开闸
     * @author liuting
     * @date 2021/7/7
     */
    initiativeOpenDevice(Imei){
        return this.requestPostForJson(controller, "/initiativeOpenDevice", Imei);
    },

    requestPost(controller, url, condition) {
        let newUrl = controller + url;
        return BaseApi.requestPost(newUrl, condition);
    },

    requestDownloadGet(controller, url, condition) {
        let newUrl = controller + url;
        return BaseApi.requestDownloadGet(newUrl, condition);
    },

    requestPostForJson(controller, url, condition) {
        let newUrl = controller + url;
        return BaseApi.requestPostForJson(newUrl, condition);
    },
    requestMultipartPost(controller, url, condition) {
        let newUrl = controller + url;
        let config={};
        config.data = condition;
        config.method = "POST";
        config.url = APIBaseURL + newUrl;
        config.contentType = false;
        config.processData = false;
        config.cache = false;
        //指定传输的数据类型
        config.headers = { 'Content-Type': 'multipart/form-data' };
        //设置响应类型
        return BaseApi.baseRequest(config);
    },

}